package com.yanqu.road.server.cmd.activity.chuhan;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.TonBingProto;
import com.yanqu.road.pb.activity.ChuHanProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ActivityModule;
import com.yanqu.road.server.protocol.*;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_CHUHAN_GET_RANK_REWARD_FROM_CROSS, desc = "")
public class ChuHanGetRankRewardFromCrossCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        TonBingProto.CrossTonBingGetRankRewardRespMsg respMsg = TonBingProto.CrossTonBingGetRankRewardRespMsg.parseFrom(packet.getBytes());
        ret = player.getModule(ActivityModule.class).getChuHanRankReward(
                respMsg.getActivityId(),
                respMsg.getConditionType(),
                respMsg.getRank(),
                respMsg.getPosition(),
                respMsg.getCampRank(),
                respMsg.getUnionId()
        );
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            ChuHanProto.ChuHanGetRankRewardRespMsg.Builder builder = ChuHanProto.ChuHanGetRankRewardRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(Protocol.S_CHUHAN_GET_RANK_REWARD, builder);
        }
    }
}
